using UnityEngine;
using Voodoo.Pattern;

public class OpponentControl : MonoBehaviour
{
	[SerializeField]
	private Rigidbody[] _hands;

	[SerializeField]
	private MoveDirection _joy;

	private Rigidbody _head;

	[SerializeField]
	private float _speedKf = 1f;

	[SerializeField]
	private Vector2 MaxBounds;

	[SerializeField]
	private Vector2 MinBounds;

	private Vector3 currentTarget;

	private float lastDecision;

	private void Awake()
	{
	}

	private void Start()
	{
		Physics.IgnoreLayerCollision(6, 6);
	}

	public void SetHead(Rigidbody h)
	{
		_head = h;
		currentTarget = new Vector3(MaxBounds.x.Range(MinBounds.x), MaxBounds.y.Range(MinBounds.y), _head.transform.position.z);
	}

	private void FixedUpdate()
	{
		if (SingletonMB<DuelModeManager>.Instance.DuelStarted && _head != null)
		{
			Vector3 normalized = (currentTarget - _head.transform.position).normalized;
			_head.velocity = new Vector3(normalized.x * _speedKf, _speedKf * normalized.y, 0f);
			if ((currentTarget - _head.transform.position).sqrMagnitude < 1f)
			{
				currentTarget = new Vector3(MaxBounds.x.Range(MinBounds.x), MaxBounds.y.Range(MinBounds.y), _head.transform.position.z);
				lastDecision = 0f;
			}
			if (Input.GetKey(KeyCode.P))
			{
				string[] obj = new string[7]
				{
					(currentTarget - _head.transform.position).sqrMagnitude.ToString(),
					"   ",
					null,
					null,
					null,
					null,
					null
				};
				Vector3 vector = currentTarget;
				obj[2] = vector.ToString();
				obj[3] = "   ";
				obj[4] = _head.transform.position.ToString();
				obj[5] = "   ";
				obj[6] = _head.velocity.ToString();
				Debug.LogError(string.Concat(obj));
			}
			lastDecision += Time.fixedDeltaTime;
			if (lastDecision > 3f)
			{
				currentTarget = new Vector3(MaxBounds.x.Range(MinBounds.x), MaxBounds.y.Range(MinBounds.y), _head.transform.position.z);
				lastDecision = 0f;
			}
		}
	}

	internal void ReplaceJoystick(MoveDirection joystick)
	{
	}
}
